#include <iostream>
#include <sstream>
#include <string>

bool is_prime(int n) {
    if (n == 1) {
        return false;
    }

    int d = 2;

    while (d * d <= n and n % d != 0) {
        d += 1;
    }

    return d * d > n;
}

void wrong_input() {
    std::cout << "Wrong input\n";
    std::exit(0);
}

int str_to_digit(const std::string& s) {
    if (s == "zero") {
        return 0;
    }

    if (s == "one") {
        return 1;
    }

    if (s == "two") {
        return 2;
    }

    if (s == "three") {
        return 3;
    }

    if (s == "four") {
        return 4;
    }

    if (s == "five") {
        return 5;
    }

    if (s == "six") {
        return 6;
    }

    if (s == "seven") {
        return 7;
    }

    if (s == "eight") {
        return 8;
    }

    if (s == "nine") {
        return 9;
    }

    wrong_input();
}

int main() {
    std::string line;
    std::getline(std::cin, line);

    std::istringstream iss(line);

    int n = 0;
    std::string word;

    while (iss >> word) {
        int number = str_to_digit(word);
        n = n * 10 + number;
    }

    if (n < 100 || n > 999) {
        wrong_input();
    }

    for (int i = 0; i < 1000; i++) {
        if (is_prime(n - i)) {
            std::cout << n - i << '\n';
            break;
        }

        if (is_prime(n + i)) {
            std::cout << n + i << '\n';
            break;
        }
    }
}
